// pages/index/index.js
Page({
    data: {
        activeTab: 'home',
        showMenu: false,
        roomName: '1202办公室',
        showLockSheet: false,
        locks: [
            { id: '1202', name: '1202办公室' },
            { id: '1320', name: '1320办公室' }
        ],
        selectedLockId: '1202'
    },
    // 菜单
    toggleMenu() { this.setData({ showMenu: !this.data.showMenu }); },
    openMenu() { this.setData({ showMenu: true }); },
    closeMenu() { this.setData({ showMenu: false }); },
    onPageTap() { if (this.data.showMenu) { this.closeMenu(); } },
    noop() {},

    // 锁选择弹窗
    openLockSheet() { this.setData({ showLockSheet: true }); },
    closeLockSheet() { this.setData({ showLockSheet: false }); },
    onLockChange(e) { this.setData({ selectedLockId: e.detail }); },
    confirmLock() {
        const cur = this.data.locks.find(i => i.id === this.data.selectedLockId);
        if (cur) { this.setData({ roomName: cur.name }); }
        this.closeLockSheet();
    },

    onAddLock() { this.closeMenu();
        wx.showToast({ title: '添加锁', icon: 'none' }); },
    onGateway() { this.closeMenu();
        wx.showToast({ title: '网关', icon: 'none' }); },
    onSettings() { this.closeMenu();
        wx.showToast({ title: '设置', icon: 'none' }); },

    onBluetooth() {
        wx.showToast({ title: '蓝牙开锁（占位）', icon: 'none' });
    },
    onRemote() {
        wx.showToast({ title: '远程开锁（占位）', icon: 'none' });
    },
    goMy() {
        wx.navigateTo({ url: '/pages/my/index' });
    },
    navKeys() { wx.navigateTo({ url: '/pages/keys/index' }); },
    navPasscode() { wx.navigateTo({ url: '/pages/passcode/index' }); },
    navCard() { wx.navigateTo({ url: '/pages/card/index' }); },
    navFingerprint() { wx.navigateTo({ url: '/pages/finger/index' }); },
    navLogs() { wx.showToast({ title: '操作记录', icon: 'none' }); },
    navSettings() { wx.showToast({ title: '设置', icon: 'none' }); }
})